package com.missyoubug.easyjtest.service.impl;

import com.missyoubug.easyjtest.dao.EasyTestDao;
import com.missyoubug.easyjtest.entity.EasyTestEntity;
import com.missyoubug.easyjtest.entity.EasyTestInfoEntity;
import com.missyoubug.easyjtest.service.EasyTestService;
import com.missyoubug.easyjtest.util.EmptyChecker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class EasyTestServiceImpl implements EasyTestService {
    @Autowired
    private EasyTestDao eseyTestDao;

    @Override
    public EasyTestEntity getTestList(EasyTestEntity easyTestEntity) {
        int page = 1;
        int pageSize = 50;

        EasyTestEntity eseyTest = new EasyTestEntity();
        //非首次进入
        if (!EmptyChecker.beanIsAllEmpty(easyTestEntity)) {
            //查询指定记录
            if (EmptyChecker.notEmpty(easyTestEntity.getId())) {
                //查询详情
                EasyTestInfoEntity info = eseyTestDao.getTestInfo(easyTestEntity.getId());
                eseyTest.setMemoryInfo(info);
            }

        }
        if (EmptyChecker.notEmpty(easyTestEntity.getPage())&&EmptyChecker.notEmpty(easyTestEntity.getPageSize())){
            page=easyTestEntity.getPage();
            pageSize=easyTestEntity.getPageSize();
        }

        List<EasyTestInfoEntity> testList = eseyTestDao.getTestList(page, pageSize);

        eseyTest.setHistoryInfo(testList);
        eseyTest.setPage(page);
        eseyTest.setPageSize(pageSize);
        int pageCount = eseyTestDao.pageCount();
        eseyTest.setPageCount(pageCount);

        return eseyTest;
}

    @Override
    public int addTestInfo(EasyTestInfoEntity entity) {
        return 0;
    }

    @Override
    public Long getTestCount() {
        return null;
    }
}
